package org.todo.service;

import java.util.List;
import org.todo.dao.CategoryDao;
import org.todo.domain.Category;

/**
 * Implementation of CategoryService interface
 * @author Matthias Braunhofer
 */
public class CategoryServiceImpl implements CategoryService {
    //injected dependency
    private CategoryDao categoryDao;

    public List<Category> getCategories(String username) {
        return categoryDao.findCategoriesForUser(username);
    }

    public void addCategory(Category category) {
        categoryDao.saveCategory(category);
    }

    public void deleteCategory(int categoryId) {
        Category category = getCategory(categoryId);
        categoryDao.deleteCategory(category);
    }

    public Category getCategory(int categoryId) {
        return categoryDao.getCategory(categoryId);
    }
    
    public void setCategoryDao(CategoryDao categoryDao) {
        this.categoryDao = categoryDao;
    }
}
